package larrys.pomodoro.daoimpl.rowmappers;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import larrys.pomodoro.domain.entity.Activity;

import org.springframework.jdbc.core.RowMapper;

public class ActivityRowMapper implements RowMapper<Activity> {

	@Override
	public Activity mapRow(ResultSet rs, int index) throws SQLException {
		long id = rs.getLong("id");
		String name = rs.getString("name");
		int estimation = rs.getInt("estimation");
		String description = rs.getString("description");
		String comment = rs.getString("comment");
		boolean finished = rs.getBoolean("finished");
		boolean permanent = rs.getBoolean("permanent");
		long userId = rs.getLong("user_id");
		Date date = rs.getTimestamp("plan_date");
		int priority = rs.getInt("priority");

		Activity activity = new Activity(id, name, userId, permanent, finished);
		activity.setEstimation(estimation);
		activity.setDescription(description);
		activity.setComment(comment);
		activity.setPlanDate(date);
		activity.setPriority(priority);

		return activity;
	}

}
